function GetDateStr(AddDayCount) {
	var dd = new Date();
	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天的日期
	var y = dd.getFullYear();
	var m = dd.getMonth()+1;//获取当前月份的日期
	var d = dd.getDate();
	return y+"-"+m+"-"+d;
}

function GetHoursStr(AddHoursCount) {
	var dd = new Date();
	dd.setHours(dd.getHours()+AddHoursCount);//获取AddHoursCount小时的日期
	return dd;
}

Date.prototype.Format = function (fmt) { 
	var o = {
			"M+": this.getMonth() + 1, //月份 
			"d+": this.getDate(), //日 
			"h+": this.getHours(), //小时 
			"m+": this.getMinutes(), //分 
			"s+": this.getSeconds(), //秒 
			"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
			"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}

function ExportExcel2(title) {
	var columns = grid.getBottomColumns();
    
    function getColumns(columns) {
        columns = columns.clone();
        for (var i = columns.length - 1; i >= 0; i--) {
            var column = columns[i];
            if (!column.field) {
                columns.removeAt(i);
            } else {
                var c = { header: column.header, field: column.field };
                columns[i] = c;
            }
        }
        return columns;
    }
    
    var columns = getColumns(columns);
    var json = mini.encode(columns);                        
    document.getElementById("excelData").value = json;
    var excelForm = document.getElementById("excelForm");
    excelForm.submit();            

}

function setCookie(c_name, value, expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	//exdate.setHours(exdate.getHours() + expiredays);
	document.cookie=c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name){
	if (document.cookie.length>0){　　//先查询cookie是否为空，为空就return ""
		c_start=document.cookie.indexOf(c_name + "=")　　//通过String对象的indexOf()来检查这个cookie是否存在，不存在就为 -1　　
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1　　//最后这个+1其实就是表示"="号啦，这样就获取到了cookie值的开始位置
			c_end=document.cookie.indexOf(";",c_start)　　//其实我刚看见indexOf()第二个参数的时候猛然有点晕，后来想起来表示指定的开始索引的位置...这句是为了得到值的结束位置。因为需要考虑是否是最后一项，所以通过";"号是否存在来判断
			if (c_end==-1) c_end=document.cookie.length　　
			return unescape(document.cookie.substring(c_start,c_end))　　//通过substring()得到了值。想了解unescape()得先知道escape()是做什么的，都是很重要的基础，想了解的可以搜索下，在文章结尾处也会进行讲解cookie编码细节
		} 
	}
	return ""
}　
function ExportExcel(title) { 
	var sTitle = $("#sTitle").val();
	var sValue = $("#sValue").val();
	var tempForm = document.createElement("form");
	tempForm.id = "tempForm1";
	tempForm.method = "post";
	tempForm.action = "../report/ExportExcel.do";
	tempForm.target="_self";
	var titlee = document.createElement("input");
	titlee.type = "hidden";
	titlee.name="title";
	titlee.value = title;
	var sTitlee = document.createElement("input");
	sTitlee.type = "hidden";
	sTitlee.name="sTitle";
	sTitlee.value = sTitle;
	var sValuee = document.createElement("input");
	sValuee.type = "hidden";
	sValuee.name="sValue";
	sValuee.value = sValue;
	tempForm.appendChild(titlee);
	tempForm.appendChild(sTitlee);
	tempForm.appendChild(sValuee);
	if(document.all){
		tempForm.attachEvent("onsubmit",function(){});        //IE
	}else{
		var subObj = tempForm.addEventListener("submit",function(){},false);    //firefox,谷歌等
	}
	document.body.appendChild(tempForm);
	/*add start by djl*/
	var Sys = {}; 
	var ua = navigator.userAgent.toLowerCase(); 
	var s; 
	(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 
		(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : 
			(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : 
				(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : 
					(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0; 
					var ieversion; 
					if (Sys.ie){ 
						ieversion = parseInt(Sys.ie); 
						if(ieversion<11){
							if(document.all){
								tempForm.fireEvent("onsubmit");
							}else{
								tempForm.dispatchEvent(new Event("submit"));//ie 11已经删掉dispatchEvent方法了
							}
						}
					}
					/*end start by djl*/
					tempForm.submit();
					document.body.removeChild(tempForm);
}  

function openWindow(title, sTitle, sValue) {    
	window.open('about:blank',title,'sTitle='+ sTitle +',sValue='+ sValue +',toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no,depended=yes');     
}

function stcdOne(stcdValue){
	var stcd = null;
	if(stcdValue.indexOf("[")>=0){
		stcd = stcdValue.split("[")[1];
		stcd = stcd.substring(0,stcd.length-1);
	}else{
		stcd = stcdValue;
	}
	return stcd;
}

function stcdMany(stcdValue){//滨海闸[51001350],大庄2号[513B1180],中心水库[632B3820],
	var stcdArr = null;
	var stcd = null;
	stcdValue = stcdValue.replace(/\s/g, "");//正则表达式去除空格
	var stcdList = '';
	if(stcdValue.indexOf("[")>=0){
		stcdArr = stcdValue.split(",");
		for(var i=0 ; i<stcdArr.length ; i++){
			if(stcdArr[i].length>8){
				stcd = stcdArr[i].split("[")[1];
				stcdList = stcdList + stcd.substring(0,stcd.length-1)+',';
			}else if(stcdArr[i].length==8){
				stcdList = stcdList + stcdArr[i]+',';
			}
		}
	}else{
		stcdList = stcdValue;
	}
	if(stcdList.substring(stcdList.length-1, stcdList.length)==','){
		stcdList = stcdList.substring(0, stcdList.length-1);
	}
	return stcdList;
}
//所有站单站列表
function stcdList(){
	$.ajax({
		url: "../report/StStbprpB.do",
		success: function (text) {
			var ss = text.split(",");
			$("#stcd").autocomplete(ss, {
				scroll: true,
				matchContains: true,
				minChars: 0
				//,multiple: true//多站
			});
		}
	});
}

//所有站多站列表
function stcdsList(){
	$.ajax({
		url: "../report/StStbprpB.do",
		success: function (text) {
			var ss = text.split(",");
			$("#stcd").autocomplete(ss, {
				scroll: true,
				matchContains: true,
				minChars: 0
				,multiple: true//多站
			});
		}
	});
}
//单站潮位站列表
function stcdListTide(){
	$.ajax({
		url: "../report/StStbprpBTide.do",
		success: function (text) {
			var ss = text.split(",");
			$("#stcd").autocomplete(ss, {
				scroll: true,
				matchContains: true,
				minChars: 0
				//,multiple: true//多站
			});
		}
	});
}
//日蒸发站列表
function stcdListDayev(){
	$.ajax({
		url: "../report/StStbprpBDayev.do",
		success: function (text) {
			var ss = text.split(",");
			$("#stcd").autocomplete(ss, {
				scroll: true,
				matchContains: true,
				minChars: 0
				//,multiple: true//多站
			});
		}
	});
}

//引排水站列表
function stcdListWdpstat(){
	$.ajax({
		url: "../report/StStbprpBWdpstat.do",
		success: function (text) {
			var ss = text.split(",");
			$("#stcd").autocomplete(ss, {
				scroll: true,
				matchContains: true,
				minChars: 0
				//,multiple: true//多站
			});
		}
	});
}

//获取当日8时时间
function getCurrentDay8hours(){
	var dd = new Date();
	var y = dd.getFullYear();
	var m = dd.getMonth()+1;//获取当前月份的日期
	var d = dd.getDate();
	var h = dd.getHours();
	if(h>=8){
		return y+"-"+m+"-"+d+" 08:00:00";
	}else{
		return y+"-"+m+"-"+(d-1)+" 08:00:00";
	}
}
//获取当前整时时间
function getDayhours(){
	var dd = new Date();
	var y = dd.getFullYear();
	var m = dd.getMonth()+1;//获取当前月份的日期
	var d = dd.getDate();
	var h = dd.getHours();
	return y+"-"+m+"-"+d+" "+h+":00:00";
}

//获取前/后n个月1号
function getMonthfirst(days){
	var dd = new Date();
	var y = dd.getFullYear();
	var m = dd.getMonth()+1;//获取当前月份的日期
	return y+"-"+(m+days)+"-1"+" 08:00:00";
}

//获得n年/n月/n日的整8点日期
function getDefaultDate(n,timeUnit) {
    var curr_date = new Date();
    if (timeUnit === 'd') {
    curr_date.setDate(curr_date.getDate() + n);
    } else if (timeUnit === 'M') {
        curr_date.setMonth(curr_date.getMonth() + n);
    } else if (timeUnit === 'y') {
        curr_date.setFullYear(curr_date.getFullYear() + n);
    }
    var strYear = curr_date.getFullYear();
    var strMonth = curr_date.getMonth()+1;
    var strDay = curr_date.getDate();

    var datastr = strYear + '-' + formatNumber(strMonth) + '-'
        + formatNumber(strDay) +' 08:00:00';
    return datastr;
}

function formatNumber(value){  
    return (value < 10 ? '0' : '') + value;  
}

//获取上月月末日期
function getMonthLast(){
	var dt = new Date();
	dt.setDate(1);
	dt.setMonth(dt.getMonth());
	cdt = new Date(dt.getTime()-1000*60*60*24);

	var y = cdt.getFullYear();
	var m = cdt.getMonth()+1;//获取当前月份的日期
	var d = cdt.getDate();
	return y+"-"+m+"-"+d+" 08:00:00";
}

//判断文件是否存在
function isfile(fileURL){
	var isfile = 0;
	var xmlhttp;
	//判断浏览器是否支持ActiveX控件
	if(window.ActiveXObject){
		//支持-通过ActiveXObject的一个新实例来创建XMLHttpRequest对象
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){//不支持
		xmlhttp = new XMLHttpRequest();
	}
	
	xmlhttp.open("GET",fileURL,false);
	xmlhttp.send();
	if(xmlhttp.readyState==4){ 
		if(xmlhttp.status==200){
			isfile = 1;//fileURL存在 
		}else if(xmlhttp.status==404){//fileURL不存在 
			
		}else{
			//其他状态 
		}
	} 
	return isfile;
}